#ifndef _LIST_H
#define _LIST_H

typedef struct list *list_t;
struct node;
struct fix_obj_pool;

typedef struct list_iter
{
	struct node **next;
	struct node *n;
}list_iter;

extern struct fix_obj_pool *list_create_obj_pool(unsigned int val_size,int default_size,int align4);

extern list_t list_create(unsigned int val_size,struct fix_obj_pool*);
extern void   list_destroy(list_t*);

extern list_iter list_begin(list_t);
extern list_iter list_end(list_t);
extern list_iter list_rbegin(list_t);
extern list_iter list_rend(list_t);

extern unsigned int list_size(list_t);
extern void   list_insert_before(list_t,list_iter,void*);
extern void   list_insert_after(list_t,list_iter,void*);
extern void   list_push_back(list_t,void*);
extern void   list_push_front(list_t,void*);
extern void   list_pop_back(list_t,void*);
extern void   list_pop_front(list_t,void*);
extern int    list_is_empty(list_t);

#ifndef LIST_INSERT_BEFORE
#define LIST_INSERT_BEFORE(TYPE,LIST,IT,VAL)\
	{TYPE val = VAL;list_insert_before(LIST,IT,&val);}
#endif

#ifndef LIST_INSERT_AFTER
#define LIST_INSERT_AFTER(TYPE,LIST,IT,VAL)\
	{TYPE val = VAL;list_insert_after(LIST,IT,&val);}
#endif

#ifndef LIST_PUSH_BACK
#define LIST_PUSH_BACK(TYPE,LIST,VAL)\
	{TYPE val = VAL;list_push_back(LIST,&val);}
#endif

#ifndef LIST_PUSH_FRONT
#define LIST_PUSH_FRONT(TYPE,LIST,VAL)\
	{TYPE val = VAL;list_push_front(LIST,&val);}
#endif

#ifndef LIST_POP_FRONT
#define LIST_POP_FRONT(TYPE,LIST)\
   ({ TYPE __result;\
       do list_pop_front(LIST,&__result);\
       while(0);\
       __result;})
#endif

#ifndef LIST_POP_BACK
#define LIST_POP_BACK(TYPE,LIST)\
   ({ TYPE __result;\
       do list_pop_back(LIST,&__result);\
       while(0);\
       __result;})
#endif




extern list_iter list_find(list_t,void*);

#ifndef LIST_FIND
#define LIST_FIND(TYPE,L,VAL)\
   ({ TYPE val = VAL;list_iter it;\
       do it = list_find(L,&val);\
       while(0);\
       it;})
#endif

extern int    list_remove(list_t,void*);

#ifndef LIST_REMOVE
#define LIST_REMOVE(TYPE,L,VAL)\
   ({ TYPE val = VAL;int ret;\
       do ret = list_remove(L,&val);\
       while(0);\
       ret;})
#endif

extern list_iter list_erase(list_t,list_iter);

extern list_iter iter_next(list_iter);
extern void *iter_get_val(list_iter,void*);
extern void  iter_set_val(list_iter,void*);
extern int   iter_is_equal(list_iter a,list_iter b);


#ifndef ITER_GET_VAL
#define ITER_GET_VAL(TYPE,NODE)\
   ({ TYPE __result;\
       do iter_get_val(NODE,&__result);\
       while(0);\
       __result;})
#endif

#ifndef ITER_SET_VAL
#define ITER_SET_VAL(TYPE,NODE,VAL)\
	{TYPE val=VAL;iter_set_val(NODE,&val);}
#endif

#endif